# CMake fragment for MicroPython port extmod component

set(MICROPY_MODULES_PORT_DIR ${CMAKE_CURRENT_LIST_DIR})

include("${CMAKE_CURRENT_LIST_DIR}/config.cmake")

set(MICROPY_INC_MODULES_PORT
    ${AOS_COMPONENTS_DIR}/osal_aos/include
    ${AOS_COMPONENTS_DIR}/ulog/include
)

if(MICROPY_PY_AIAGENT)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_AIAGENT=1)

    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/aiagent/modaiagent.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/aiagent/aiagent.c)
endif()

if(M5STACK_CORE2)
    set(BOARD_M5STACKCORE2 TRUE)
endif()

if(IDF_TARGET STREQUAL "esp32")
    list(APPEND MICROPY_INC_MODULES_PORT $ENV{IDF_PATH}/components/soc/soc/esp32/include)
elseif(IDF_TARGET STREQUAL "esp32c3")
    list(APPEND MICROPY_INC_MODULES_PORT $ENV{IDF_PATH}/components/soc/esp32c3/include)
elseif(IDF_TARGET STREQUAL "esp32s2")
    list(APPEND MICROPY_INC_MODULES_PORT $ENV{IDF_PATH}/components/soc/esp32s2/include)
elseif(IDF_TARGET STREQUAL "esp32s3")
    list(APPEND MICROPY_INC_MODULES_PORT $ENV{IDF_PATH}/components/soc/esp32s3/include)
endif()

if(MICROPY_PY_ALIYUNIOT)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_ALIYUNIOT=1)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/aliyunIoT/modaliyunIoT.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/aliyunIoT/module_aiot_activeinfo.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/aliyunIoT/module_aiot_device.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/aliyunIoT/module_aiot_dynreg.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/aliyunIoT/module_aiot_gateway.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/aliyunIoT/module_aiot_mqtt.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/aliyunIoT/module_aiot_ntp.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/aliyunIoT/module_aiot_upload.c)
    list(APPEND MICROPY_INC_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/aliyunIoT)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/linksdk/components/data-model)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/linksdk/components/dynreg)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/linksdk/components/subdev)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/linksdk/components/devinfo)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/linksdk/components/ntp)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/linksdk/components/mqtt-upload)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/linksdk/core)
 endif()

if(MICROPY_PY_BLE)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_BLE=1)
    list(APPEND MICROPY_DEF_MODULES_PORT CONFIG_BT=1)

    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/ble/modble.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/ble/bt_gatts_adapter.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/ble/bt_host_adapter.c)
    list(APPEND MICROPY_INC_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/ble)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/ble_host/bt_host/include)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/ble_host/include)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/ble_host/include)
endif()

if(MICROPY_PY_CHANNEL_ENABLE)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_CHANNEL_ENABLE=1)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/online_upgrade/modonline_upgrade.c)
endif()

if(MICROPY_PY_HTTP)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_HTTP=1)
    if(ESP_PLATFORM)
        list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/network/http/esp32/modhttp.c)
    endif()
    if(HAAS_PLATFORM)
        list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/network/http/aos/modhttp.c)
        list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/network/http/aos/httpclient.c)
        list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/http/include)
    endif()
    list(APPEND MICROPY_INC_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/network/http)
endif()

if(MICROPY_PY_MODBUS)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_MODBUS=1)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/modbus/modbus.c)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/mbmaster/include)
endif()

if(MICROPY_PY_KV)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_KV=1)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/kv/modkv.c)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/kv/include)
endif()

if(MICROPY_PY_OTA)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_OTA=1)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/ota/modota.c)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/ota/include)
endif()

if(MICROPY_PY_OSS)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_OSS=1)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/oss/modoss.c)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/oss/include)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/oss/src)
elseif(MICROPY_PY_OSS_HTTP)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_OSS_HTTP=1)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/oss/modosshttp.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/oss/byhttp/aliot_base64.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/oss/byhttp/aliot_hmac.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/oss/byhttp/aliot_httpapi_oss.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/oss/byhttp/aliot_sha1.c)
    list(APPEND MICROPY_INC_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/oss/byhttp)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/http/include)
endif()

if(MICROPY_PY_UCLOUD_AI)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_UCLOUD_AI=1)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/aiagent/aiagent.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/aiagent/modaiagent.c)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/ai_agent/include)
endif()

if(MICROPY_PY_MINICV)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_MINICV=1)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/modminicv.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/datainput.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/imagecodec.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/imageproc.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/ml.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/ui.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/videocodec.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/base/modules/c/src/WrapperIHaasDataInput.cpp)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/base/modules/c/src/WrapperIHaasImageCodec.cpp)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/base/modules/c/src/WrapperIHaasImageProc.cpp)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/base/modules/c/src/WrapperIHaasML.cpp)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/base/modules/c/src/WrapperIHaasUI.cpp)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/base/modules/c/src/WrapperIHaasVideoCodec.cpp)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/base/modules/core/src/HaasImageUtils.cpp)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/base/modules/ml/src/HaasML.cpp)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/base/modules/ml/src/HaasMLCloud.cpp)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/base/modules/ml/src/HaasMLMnn.cpp)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/base/modules/ml/src/HaasMLOlda.cpp)
    list(APPEND MICROPY_INC_MODULES_PORT ${HAAS_ENGINE_DIR}/modules/minicv)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/ucloud_ai/include)
endif()

if(MICROPY_PY_UCAMERA)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_UCAMERA=1)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/ucamera/moducamera.c)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/ucamera/include)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/ucamera/include/device/wifi)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/ucamera/include/device/uart)
endif()

if(MICROPY_PY_DRIVER)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_DRIVER=1)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/driver/moddriver.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/driver/board_mgr.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/driver/pwm.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/driver/adc.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/driver/timer.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/driver/i2c.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/driver/spi.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/driver/uart.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/driver/gpio.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/driver/wdt.c)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/amp_adapter/include/peripheral)
    if(HAAS_PLATFORM)
        list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/drivers/peripheral/gpio/include)
        list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/drivers/core/base/include)
    endif()
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/cjson/include)
endif()

if(MICROPY_PY_AUDIO)
    include("${MICROPY_MODULES_PORT_DIR}/audio/CMakeLists.txt")
endif()

if(MICROPY_PY_SNTP)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_SNTP=1)

    if(HAAS_PLATFORM)
        list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/sntp/aos/modsntp.c)
        list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/sntp/include)
    elseif(ESP_PLATFORM)
        list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/sntp/esp32/modsntp.c)
    endif()
endif()

if(MICROPY_PY_LVGL)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_LVGL=1)
    list(APPEND MICROPY_INC_MODULES_PORT ${MICROPY_DIR}/lib/lv_bindings)
    list(APPEND MICROPY_INC_MODULES_PORT ${MICROPY_DIR}/lib/lv_bindings/lvgl)
    list(APPEND MICROPY_INC_MODULES_PORT ${MICROPY_DIR}/lib/lv_bindings/lvgl/src)

    list(APPEND MICROPY_INC_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/display)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/freetype/include)
    if(HAAS_PLATFORM)
        #list(APPEND MICROPY_DEF_MODULES_PORT LV_CONF_INCLUDE_SIMPLE=1)
        list(APPEND MICROPY_INC_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/display/haas)
        list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/drivers/external_device/ft6336/include)
        list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/display/haas/moddisplay.c)
    endif()
    if(ESP_PLATFORM)
        list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/drivers/external_device/m5driver/i2c_manager)
        list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/drivers/external_device/m5driver/i2c_manager/i2c_manager)
        list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/drivers/external_device/m5driver/axp192)
        list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/drivers/external_device/m5driver/lvgl_esp32_drivers)
        list(APPEND MICROPY_INC_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/display/esp32)
        list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/display/esp32/moddisplay.c)
    endif()
endif()

if(MICROPY_PY_TFT)
    if(ESP_PLATFORM)
        list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_TFT=1)
        list(APPEND MICROPY_INC_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/display/esp32)
        list(APPEND MICROPY_INC_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/display/esp32/tft)
        list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/display/esp32/modtft.c)
        file(GLOB_RECURSE TFT_SOURCES ${MICROPY_MODULES_PORT_DIR}/display/esp32/tft/*.c)
        list(APPEND MICROPY_SOURCE_MODULES_PORT ${TFT_SOURCES})
    endif()
endif()

if(MICROPY_PY_BLECFG)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_BLECFG=1)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/netconfig/blecfg.c)
endif()

if(MICROPY_PY_NETMGR)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_NETMGR=1)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/netmgr/modnetmgr.c)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/uservice/include)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/netmgr/include)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/amp_adapter/include)
endif()

if(MICROPY_PY_ULOG)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_ULOG=1)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/ulog/modulog.c)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/ulog/include)
endif()
